//
//  MessageViewController.m
//  chongwu
//
//  Created by 隼目 on 2021/9/15.
//

#import "MessageViewController.h"
#import "MessageTableViewCell.h"
@interface MessageViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)BaseTableView *tableView;
@property(nonatomic,strong)NSArray<UIImageView *> *imageArr;
@property(nonatomic,strong)NSArray<UILabel *> *titleArr;
@property(nonatomic,strong)NSArray<UILabel *> *xianArr;

@property(nonatomic,assign)NSInteger selectSendOrCollect;
@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=rgba(245, 246, 246, 1);
    
    [self cretTopView];
}

-(void)cretTopView{
  
    UIView *btnView=[UIView new];
    [self.view addSubview:btnView];
    [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(30*_mainHeight);
        make.right.mas_equalTo(-30*_mainWidth);
        make.top.mas_equalTo(20*_mainHeight);
        make.height.mas_equalTo(204*_mainHeight);
    }];
    btnView.backgroundColor=[UIColor whiteColor];
    btnView.layer.cornerRadius=25*_mainWidth;
    btnView.layer.shadowColor = rgba(74,31,0,0.1).CGColor;
    btnView.layer.shadowOffset = CGSizeMake(0,0);
    btnView.layer.shadowOpacity = 1;
    btnView.layer.shadowRadius = 2;
    
    UIView *xianView=[UIView new];
    [btnView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
        make.height.mas_equalTo(129*_mainHeight);
        make.width.mas_equalTo(1.5*_mainWidth);
    }];
    xianView.backgroundColor=rgba(151,151,151,1);
    
    UIView *leftView2=[UIView new];
    [btnView addSubview:leftView2];
    [leftView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(xianView.mas_left);
    }];
    leftView2.tag=0;
    leftView2.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSendOrCollect:)];
    [leftView2 addGestureRecognizer:tapGesture];
    

    UILabel *leftLabel=[UILabel new];
    [leftView2 addSubview:leftLabel];
    [leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(42*_mainWidth);
    }];
    [leftLabel layoutIfNeeded];
    leftLabel.text=@"寄件通知";
    leftLabel.font=[UIFont fontWithName:@"Helvetica-Bold" size:autoScaleW(36)];
    leftLabel.textColor=rgba(47,47,47,1);
    
    UILabel *leftNum=[UILabel new];
    [leftView2 addSubview:leftNum];
    [leftNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(leftLabel.mas_right);
        make.centerY.mas_equalTo(leftLabel.mas_top);
        make.height.mas_equalTo(_mainHeight*36);
        make.width.mas_equalTo(_mainWidth*50);
    }];
    leftNum.textAlignment=NSTextAlignmentCenter;
    leftNum.text=@"99+";
    leftNum.textColor=[UIColor whiteColor];
    leftNum.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(22)];
    [leftNum layoutIfNeeded];
    leftNum.backgroundColor=rgba(253,79,25,1);
    leftNum.layer.masksToBounds=YES;
    leftNum.layer.cornerRadius=16*_mainHeight;
   
    UIImageView *leftImage=[UIImageView new];
    [leftView2 addSubview:leftImage];
    [leftImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(leftLabel.mas_bottom).mas_equalTo(21*_mainHeight);
        make.width.height.mas_equalTo(55*_mainWidth);
    }];
    leftImage.image=[UIImage imageNamed:@"jijian-1"];
    
    UIView *rightView=[UIView new];
    [btnView addSubview:rightView];
    [rightView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
        make.left.mas_equalTo(xianView.mas_right);
    }];
    rightView.tag=1;
    rightView.userInteractionEnabled=YES;
    UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectSendOrCollect:)];
    [rightView addGestureRecognizer:tapGesture2];
    
    UILabel *rightLabel=[UILabel new];
    [rightView addSubview:rightLabel];
    [rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(42*_mainWidth);
    }];
    [rightLabel layoutIfNeeded];
    rightLabel.text=@"寄件通知";
    rightLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
    rightLabel.textColor=rgba(47,47,47,1);
    
    UILabel *rightNum=[UILabel new];
    [rightView addSubview:rightNum];
    [rightNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(rightLabel.mas_right);
        make.centerY.mas_equalTo(rightLabel.mas_top);
        make.height.mas_equalTo(_mainHeight*36);
        make.width.mas_equalTo(_mainWidth*50);
    }];
    rightNum.textAlignment=NSTextAlignmentCenter;
    rightNum.text=@"4";
    rightNum.textColor=[UIColor whiteColor];
    rightNum.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(22)];
    [rightNum layoutIfNeeded];
    rightNum.backgroundColor=rgba(213,213,213,1);
    rightNum.layer.masksToBounds=YES;
    rightNum.layer.cornerRadius=16*_mainHeight;
    
    
    UIImageView *rightImage=[UIImageView new];
    [rightView addSubview:rightImage];
    [rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(0);
        make.top.mas_equalTo(leftLabel.mas_bottom).mas_equalTo(21*_mainHeight);
        make.width.height.mas_equalTo(55*_mainWidth);
    }];
    rightImage.image=[UIImage imageNamed:@"shoujianhuise"];
    
    self.imageArr=@[leftImage,rightImage];
    self.titleArr=@[leftLabel,rightLabel];
    self.xianArr=@[leftNum,rightNum];
    
    self.tableView=[BaseTableView new];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(btnView.mas_bottom);
        make.bottom.mas_equalTo(-TAB_BAR_HEIGHT);
    }];
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.backgroundColor=rgba(245, 246, 246, 1);
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
}
-(void)selectSendOrCollect:(UITapGestureRecognizer *)tap{
    self.selectSendOrCollect=tap.view.tag;
   
    for (int i=0; i<2; i++) {
        UILabel *label=self.titleArr[i];
        UILabel *numLabel=self.xianArr[i];
        if (tap.view.tag==i) {
            numLabel.backgroundColor=rgba(253,79,25,1);
            label.font=[UIFont fontWithName:@"Helvetica-Bold" size:autoScaleW(36)];
        }else{
            numLabel.backgroundColor=rgba(213,213,213,1);
            label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
        }
    }
    UIImageView *leftImage=self.imageArr[0];
    UIImageView *rightImage=self.imageArr[1];
    if (tap.view.tag==0) {
        leftImage.image=[UIImage imageNamed:@"jijian-1"];
        rightImage.image=[UIImage imageNamed:@"shoujianhuise"];
    }else if (tap.view.tag==1) {
        leftImage.image=[UIImage imageNamed:@"jijianhuise"];
        rightImage.image=[UIImage imageNamed:@"shoujian"];
    }
  
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MessageTableViewCell *cell=[[MessageTableViewCell alloc] init];
    cell.tag=indexPath.row;
    [cell setFrame:CGRectMake(0, 0, _mainW, [cell creatView])];
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
